package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.generator.entity.TbUserEntity;
import io.renren.modules.generator.service.TbUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 用户
 *
 * @author Xiaotianyu
 * @email 805007911@qq.com
 * @date 2021-10-13 15:25:04
 */
@RestController
@RequestMapping("generator/tbuser")
@Api("管理员端-用户相关增删改查接口")
public class TbUserController {
    @Autowired
    private TbUserService tbUserService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("generator:tbuser:list")
    @ApiOperation("分页查询")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tbUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("generator:tbuser:info")
    @ApiOperation("根据ID查询")
    public R info(@PathVariable("userId") Long userId){
		TbUserEntity tbUser = tbUserService.getById(userId);

        return R.ok().put("tbUser", tbUser);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("generator:tbuser:save")
    @ApiOperation("保存")
    public R save(@RequestBody TbUserEntity tbUser){
		tbUserService.save(tbUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @RequiresPermissions("generator:tbuser:update")
    @ApiOperation("更新")
    public R update(@RequestBody TbUserEntity tbUser){
		tbUserService.updateById(tbUser);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("generator:tbuser:delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Long[] userIds){
		tbUserService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
